StaffPositionView = Ext
		.extend(
				Ext.Panel,
				{
					constructor : function(a) {
						Ext.applyIf(this, a);
						this.initUIComponents();
						StaffPositionView.superclass.constructor.call(this, {
							id : "StaffPositionView",
							title : "职位人员管理",
							region : "center",
							layout : "border",
							border : false,
							iconCls : "menu-position",
							items : [ this.gridPanel, this.searchPanel,
									this.staffPositionTreePanel ],
							keys : [ {
								key : Ext.EventObject.ENTER,
								fn : this.search,
								scope : this
							}, {
								key : Ext.EventObject.ESC,
								fn : this.reset,
								scope : this
							} ]
						});
					},
					initUIComponents : function() {
						this.topbar = new Ext.Toolbar({
							defaultType : "button",
							items : [
									{
										text : "添加",
										iconCls : "add-user",
										scope : this,
										handler : function() {
											var f = Ext.getCmp(
													"staffPositionViewPositionTreePanel")
													.getSelectionModel()
													.getSelectedNode();
											if (f != null && f.id > 0) {
												new StaffPositionForm({
													positionId : f.id,
													positionName : f.text
												}).show();
											} else {
												new StaffPositionForm({}).show();
											}
										}
									}, "-", {
										text : "删除",
										iconCls : "btn-delete",
										scope : this,
										handler : this.removeByIds
									} ]
						});
						this.searchPanel = new Ext.FormPanel({
							id : "StaffPositionViewSearchPanel",
							region : "north",
							layout : "form",
							border : false,
							height : 40,
							frame : false,
							layoutConfig : {
								padding : "5px",
								align : "middle"
							},
							items : [ {
								fieldLabel : "请输入搜索条件",
								layout : "column",
								xtype : "container",
								style : "margin-top:8px;",
								border : false,
								defaults : {
									xtype : "label",
									height : 25,
									border : false
								},
								layoutConfig : {
									align : "middle"
								},
								items : [ /*{
									style : "margin:5px 5px 5px 5px;",
									text : "员工工号"
								}, {
									columnWidth : 0.2,
									xtype : "textfield",
									name : "Q_appUser.username_S_LK",
									maxLength : 256
								},*/ {
									style : "margin:5px 5px 5px 5px;",
									text : "员工姓名"
								}, {
									columnWidth : 0.2,
									xtype : "textfield",
									name : "Q_staff.name_S_LK",
									maxLength : 256
								}, {
									style : "margin:5px 5px 5px 5px;",
									text : "主职位(是/否)"
								}, {
									columnWidth : 0.2,
									xtype : "combo",
									hiddenName : "Q_isMain_SN_EQ",
									mode : "local",
									triggerAction : "all",
									editable : false,
									store : [[ "1", "是" ], [ "0", "否" ] ],
									emptyText : "全部"
								}, {
									style : "margin-left:5px;",
									xtype : "button",
									text : "搜索",
									iconCls : "search",
									scope : this,
									handler : this.search
								}, {
									xtype : "button",
									text : "清空",
									iconCls : "reset",
									scope : this,
									handler : this.reset
								} ]
							} ]
						});
						this.gridPanel = new HT.GridPanel(
								{
									id : "StaffPositionStaffGrid",
									title : "职位人员列表",
									region : "center",
									tbar : this.topbar,
									rowActions : true,
									url : __ctxPath + "/system/listStaffPos.do",
									trackMouseOver : true,
									disableSelection : false,
									loadMask : true,
									viewConfig : {
										forceFit : true,
										enableRowBody : false,
										showPreview : false
									},
									fields : [  "id", "staff", "position", "isMain" ],
									columns : [
											{
												header : "id",
												dataIndex : "id",
												hidden : true
											},									
											/*{
												header : "员工工号",
												dataIndex : "staff",
												menuDisabled : true,
												sortable : true,
												renderer : function(f) {
													return f.staffName;
												}
											},*/
											{
												header : "员工姓名",
												dataIndex : "staff",
												menuDisabled : true,
												sortable : true,
												renderer : function(f) {
													return f.name;
												}
											},
											{
												header : "职位",
												dataIndex : "position",
												menuDisabled : true,
												sortable : true,
												renderer : function(f) {
													return f.positionName;
												}
											},
											{
												header : "主职位(是/否)",
												dataIndex : "isMain",
												menuDisabled : true,
												sortable : true,
												renderer : function(f) {
													return f == 1 ? "是" : "否";
												}
											},
											new Ext.ux.grid.RowActions(
													{
														header : "管理",
														width : 100,
														actions : [
																{
																	iconCls : "btn-delete",
																	qtip : "删除",
																	style : "margin : 0 3px 0 3px"
																},
																{
																	iconCls : "btn-edit",
																	qtip : "编辑",
																	style : "margin : 0 3px 0 3px"
																}/*,
																{
																	iconCls : "btn-showDetail",
																	qtip : "查看职位信息",
																	style : "margin : 0 3px 0 3px"
																}*/ ],
														listeners : {
															scope : this,
															"action" : this.onRowActions
														}
													}) ]
								});
						this.gridPanel.addListener("rowdblclick", function(f,
								h, g) {
							f.getSelectionModel().each(function(i) {
								new StaffPositionForm({
									id : i.data.id,
									positionName : i.data.position.positionName
								}).show();
							});
						});
						
												
						this.staffPositionTreePanel = new Ext.tree.TreePanel(
								{
									id : "staffPositionViewPositionTreePanel",
									region : "west",
									border : false,
									width : 200,
									collapsible : true,
									autoScroll : true,
									split : true,
									title : "职位信息列表",
									tbar : new Ext.Toolbar(
											{
												defaultType : "button",
												items : [
														{
															text : "刷新",
															iconCls : "btn-refresh",
															handler : function() {
																Ext
																		.getCmp("staffPositionViewPositionTreePanel").root
																		.reload();
															}
														},
														{
															text : "展开",
															iconCls : "btn-expand",
															handler : function() {
																Ext
																		.getCmp(
																				"staffPositionViewPositionTreePanel")
																		.expandAll();
															}
														},
														{
															text : "收起",
															iconCls : "btn-collapse",
															handler : function() {
																Ext
																		.getCmp(
																				"staffPositionViewPositionTreePanel")
																		.collapseAll();
															}
														} ]
											}),
									loader : new Ext.tree.TreeLoader({
										url : __ctxPath + "/system/treeLoadStaffPos.do"
									}),
									root : new Ext.tree.AsyncTreeNode({
										expanded : true
									}),
									rootVisible : false,
									listeners : {
										"click" : this.clickNode
									}
								});
						this.staffPositionTreePanel.on("contextmenu", d,
								this.staffPositionTreePanel);
						var e = new Ext.menu.Menu({
							id : "staffPosition",
							items : [ {
								text : "新增职位信息",
								iconCls : "btn-add",
								scope : this,
								handler : c
							}, {
								text : "修改职位信息",
								iconCls : "btn-edit",
								scope : this,
								handler : a
							}, {
								text : "删除职位信息",
								iconCls : "btn-delete",
								scope : this,
								handler : b
							} ]
						});
						function d(f, g) {
							staffPositionSelected = new Ext.tree.TreeNode({
								id : f.id,
								text : f.text
							});
							e.showAt(g.getXY());
						}
						function c() {
							var f = staffPositionSelected.id;
							if (f > 1) {
								new PositionForm({
									parentId : f
								}).show();
							} else {
								new PositionForm({
									parentId : 1
								}).show();
							}
						}
						function a() {
							var f = staffPositionSelected.id;
							if (f > 1) {
								new PositionForm({
									id : f
								}).show();
							} 
						}
						function b() {
							var f = staffPositionSelected.id;
							if (f > 1) {
								Ext.Msg
										.confirm(
												"操作提示",
												"你真的要删除该职位信息吗？",
												function(g) {
													if (g == "yes") {
														var h = Ext
																.getCmp("staffPositionViewPositionTreePanel");
														Ext.Ajax
																.request({
																	url : __ctxPath
																			+ "/system/deletePosition.do?ids="
																			+ f,
																	method : "post",
																	waitMsg : "数据正在提交，请稍后...",
																	success : function(
																			i,
																			k) {
																		var j = Ext.util.JSON
																				.decode(i.responseText);
																		if (j.success) {
																			Ext.ux.Toast
																					.msg(
																							"操作提示",
																							"删除该职位信息操作成功！");
																			h.root
																					.reload();
																		} else {
																			Ext.MessageBox
																					.show({
																						title : "操作提示",
																						msg : j.message,
																						buttons : Ext.MessageBox.OK,
																						icon : "ext-mb-error"
																					});
																		}
																	}
																});
													}
												});
							}
						}
						
//						载入前带查询条件的翻页
						
						Ext.getCmp("StaffPositionStaffGrid").getStore().on('beforeload', function(store, options) {  
							
							var p = Ext.getCmp("staffPositionViewPositionTreePanel").getSelectionModel().getSelectedNode();
							var e = Ext.getCmp("StaffPositionViewSearchPanel");
							var b = e.getCmpByName("Q_staff.name_S_LK")
							.getValue();
//					         var g = e.getCmpByName("Q_appUser.fullname_S_LK")
//							.getValue();
					         var a = e.getCmpByName("Q_isMain_SN_EQ").getValue();     
					var new_params = {
							"Q_staff.name_S_LK" : b
							//"Q_appUser.fullname_S_LK" : g
							
					                };  
					
					if (p != null && p.id > 1) {
						new_params["Q_position.id_L_EQ"] = p.id;
					}
					if (a == "0") {
						new_params["Q_isMain_SN_EQ"] = "0";
					} else if (a == "1") {
							new_params["Q_isMain_SN_EQ"] = "1";
						}

					Ext.apply(options.params, new_params); 
					});
						
						
						
					},
					onRowActions : function(c, a, d, e, b) {
						switch (d) {
						case "btn-showDetail":
							this.showDetail.call(this, a);
							break;
						case "btn-edit":
							this.editById.call(this, a);
							break;
						case "btn-delete":
							this.removeById.call(this, a.data.id);
							break;
						default:
							break;
						}
					},
					reset : function() {
						var a = Ext.getCmp("StaffPositionViewSearchPanel");
						a.getForm().reset();
					},
					search : function() {
						this.clickNode(null);
					},
					editById : function(a) {
						new StaffPositionForm({
							id : a.data.id,
							positionName : a.data.position.positionName
						}).show();
					},
					showDetail : function(a) {
						var b = a.data.staff;
						UserJobDetailForm.show(b.id, b.name);
					},
					removeById : function(a) {
						Ext.Msg
								.confirm(
										"操作提示",
										"你真的要删除所选数据吗？",
										function(b) {
											if (b == "yes") {
												Ext.Ajax
														.request({
															url : __ctxPath
																	+ "/system/deleteStaffPos.do",
															params : {
																ids : a
															},
															method : "post",
															waitMsg : "数据正在提交，请稍后...",
															success : function(
																	c, d) {
																Ext.ux.Toast
																		.msg(
																				"操作提示",
																				"数据删除成功！");
																Ext
																		.getCmp(
																				"StaffPositionStaffGrid")
																		.getStore()
																		.reload();
															},
															failure : function() {
																Ext.ux.Toast
																		.msg(
																				"操作提示",
																				"对不起，数据提交失败！");
															}
														});
											}
										});
					},
					removeByIds : function() {
						var d = Ext.getCmp("StaffPositionStaffGrid");
						var a = d.getSelectionModel().getSelections();
						if (a.length > 0) {
							var c = new Array();
							for (var b = 0; b < a.length; b++) {
								c.push(a[b].data.id);
							}
							this.removeById(c);
						} else {
							Ext.ux.Toast.msg("操作提示", "对不起，请选择要删除的员工信息！");
						}
					},
					clickNode : function(f) {
						
						if(f){
							Ext.getCmp("staffPositionViewPositionTreePanel").getSelectionModel().clearSelections();
							Ext.getCmp("staffPositionViewPositionTreePanel").getSelectionModel().select(f);
							}
//						var e = Ext.getCmp("StaffPositionViewSearchPanel");
//						var b = e.getCmpByName("Q_appUser.username_S_LK")
//								.getValue();
//						var g = e.getCmpByName("Q_appUser.fullname_S_LK")
//								.getValue();
//						var a = e.getCmpByName("Q_isMain_SN_EQ").getValue();
						var c = Ext.getCmp("StaffPositionStaffGrid").getStore();
						var d = {
							start : 0,
							limit : 25
//							"Q_appUser.username_S_LK" : b,
//							"Q_appUser.fullname_S_LK" : g
						};
//						if (f != null && f.id > 0) {
//							d["userJob.job.jobId"] = f.id;
//						}
//						if (a == "0") {
//							d["Q_isMain_SN_EQ"] = "";
//						} else {
//							if (a == "1") {
//								d["Q_isMain_SN_EQ"] = "1";
//							}
//						}
						c.reload({
							params : d
						});
					}
				});